package cn.itgod.service.impl;
import cn.itgod.dto.EmployeeLoginDTO;
import cn.itgod.mapper.empMapper;
import cn.itgod.service.EmpService;
import cn.itgod.utils.EncryptUtils;
import cn.itgod.utils.JwtUtils;
import cn.itgod.vo.EmployeeLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public class EmpServiceImpl  implements EmpService {
    @Autowired
    private empMapper empmapper;

    /**
     * 根据用户名密码查询用户信息，如果信息正确则返回jwt令牌！
     * @param employeeLoginDTO
     * @return
     */
    @Override
    public EmployeeLoginVo empLogin(EmployeeLoginDTO employeeLoginDTO) {
        /*employeeLoginDTO.setPassword( EncryptUtils.getEncryption(employeeLoginDTO.getPassword()));*/
        EmployeeLoginVo empmessage = empmapper.login(employeeLoginDTO);
        if (empmessage!=null){
            Map<String, Object> datamap = new HashMap<>();
            datamap.put( "id",empmessage.getId());
            datamap.put( "username",empmessage.getUsername());
            datamap.put( "name",empmessage.getName());
            /*调用JwtUtils工具类的方法*/
            empmessage.setToken(JwtUtils.spawJwt(datamap));
            return empmessage;
        }
        return  null;
    }
}
